package org.jeecg.common.datasource.config;

import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.Map;

@Component
@ConfigurationProperties(prefix = "spring.datasource")
@Configuration
public class DataSourceConfig {
    private static final Logger LG = LoggerFactory.getLogger(DataSourceConfig.class);
    /**
     * 多数据源集合
     */
    private Map<String, HikariDataSource> dbList;

    /**
     * 默认数据源
     */
    private String defaultName;


    public Map<String, HikariDataSource> getDbList() {
        return dbList;
    }

    public void setDbList(Map<String, HikariDataSource> dbList) {
        this.dbList = dbList;
        Iterator<String> iterator = dbList.keySet().iterator();
        while(iterator.hasNext()){
            LG.info("【数据库】数据源名称：{}", iterator.next());
        }
    }

    public String getDefaultName() {
        return defaultName;
    }

    public void setDefaultName(String defaultName) {
        this.defaultName = defaultName;
        LG.info("【数据库】默认数据源名称：{}", this.defaultName);
    }
}
